﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class UserRole : IAccessible<U_UserRole, UserRole>, ILogicEntity<U_UserRole, UserRole>
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public int RoleID { get; set; }
        public Role role { get; set; }

        public UserRole LoadRole(U_Role u_role)
        {
            this.role = new Role().Set(u_role);
            return this;
        }
        protected override void Covariant(U_UserRole model)
        {
            if (model != null)
            {
                this.ID = model.ID;
                this.RoleID = model.RoleID;
                this.UserName = model.UserName;
            }
        }

        protected override U_UserRole Inverter(UserRole model)
        {
            if (model != null)
            {
                return new U_UserRole()
                {
                    ID = model.ID,
                    RoleID = model.RoleID,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public UserRole Set(U_UserRole dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
